﻿Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Windows.Media.Effects


Public Class BrightContrastEffect
    Inherits ShaderEffect

    'Usage:

    '<Image Source="img.jpg">
    '        <Image.Effect>
    '            <l:BrightContrastEffect 
    '                Brightness="{Binding ElementName=bVal, Path=Value}"
    '                Contrast="{Binding ElementName=cVal, Path=Value}"/>
    '        </Image.Effect>
    '    </Image>

    Public Sub New()
        If BrightContrastEffect.m_Shader.UriSource Is Nothing Then
            BrightContrastEffect.m_Shader.UriSource = New Uri("pack://application:,,,/eComic2010;component/bricon.ps")
        End If
        PixelShader = m_Shader
        UpdateShaderValue(InputProperty)
        UpdateShaderValue(BrightnessProperty)
        UpdateShaderValue(ContrastProperty)
    End Sub

    Private Shared m_Shader As New PixelShader()

    Public Property Input As Brush
        Get
            Return DirectCast(GetValue(inputproperty), Brush)
        End Get
        Set(ByVal value As Brush)
            SetValue(inputproperty, value)
        End Set
    End Property
    Public Shared ReadOnly InputProperty As DependencyProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", GetType(BrightContrastEffect), 0)

    Public Property Brightness As Double
        Get
            Return DirectCast(GetValue(BrightnessProperty), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(BrightnessProperty, value)
        End Set
    End Property
    Public Shared ReadOnly BrightnessProperty As DependencyProperty = DependencyProperty.Register("Brightness", GetType(Double), GetType(BrightContrastEffect), New UIPropertyMetadata(0.0, PixelShaderConstantCallback(0)))

    Public Property Contrast As Double
        Get
            Return DirectCast(GetValue(ContrastProperty), Double)
        End Get
        Set(ByVal value As Double)
            SetValue(ContrastProperty, value)
        End Set
    End Property
    Public Shared ReadOnly ContrastProperty As DependencyProperty = DependencyProperty.Register("Contrast", GetType(Double), GetType(BrightContrastEffect), New UIPropertyMetadata(0.0, PixelShaderConstantCallback(1)))





End Class
